package com.gsoe.problem.controller.admin;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gsoe.base.model.PageResult;
import com.gsoe.base.model.Result;
import com.gsoe.problem.dto.*;
import com.gsoe.problem.po.Exam;
import com.gsoe.problem.service.ExamProblemService;
import com.gsoe.problem.service.ExamRegisterUserService;
import com.gsoe.problem.service.ExamService;
import com.gsoe.problem.vo.ExamAdminVO;
import com.gsoe.problem.vo.ExamDetailVO;
import com.gsoe.problem.vo.NeedPeopleProblemVO;
import com.gsoe.problem.vo.ProblemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/problem/exam/admin")
public class ExamAdminController {
    @Autowired
    ExamService examService;

    @Autowired
    ExamRegisterUserService examRegisterUserService;

    @Autowired
    ExamProblemService examProblemService;

    @PostMapping("/getExamList")
    public Result<PageResult<ExamAdminVO>> getExamList(@RequestBody ExamDTO examDTO) {
        return Result.success(examService.getExamAdminList(examDTO));
    }

    @GetMapping("/getUserExamDetail/{examId}")
    @SaCheckPermission("exam_user_detail_look")
    public Result<ExamDetailVO> getUserExamDetail(@PathVariable Long examId) {
        return Result.success(examRegisterUserService.getUserExamDetail(examId));
    }


    @PostMapping("/saveExam")
    @SaCheckPermission("exam_add_update")
    public Result<String> saveExam(@RequestBody SaveExamDTO savExamDTO) {
        examService.saveExam(savExamDTO);
        return Result.success("ok");
    }

    @DeleteMapping("/del/{id}")
    @SaCheckPermission("exam_add_update")
    private Result<String> delExam(@PathVariable Long id) {
        examService.delExam(id);
        return Result.success("ok");
    }

    @GetMapping("/getExamById/{id}")
    @SaCheckPermission("exam_add_update")
    public Result<SaveExamDTO> getExamById(@PathVariable Long id) {
        return Result.success(examService.getExamById(id));
    }

    @PostMapping("/creatExamByRandom")
    @SaCheckPermission("exam_add_update")
    public Result<Long> creatExamByRandom(@RequestBody CreatExamByRandomDTO creatExamByRandomDTO) {
        return Result.success(examService.creatExamByRandom(creatExamByRandomDTO));
    }

    @PostMapping("/addTeachComment")
    @SaCheckPermission("teach_comment_add_update")
    public Result<String> addTeachComment(@RequestBody TeacherCommentDTO teacherCommentDTO){
        examRegisterUserService.addTeachComment(teacherCommentDTO);
        return Result.success("ok");
    }

    @PutMapping("/updateStatus/{id}/{status}")
    @SaCheckPermission("exam_add_update")
    public Result<String> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        examRegisterUserService.updateStatus(id,status);
        return Result.success("ok");
    }

    @DeleteMapping("/delRegisterUserById/{id}")
    @SaCheckPermission("exam_add_update")
    public Result<String> delRegisterUserById(@PathVariable Long id) {
        examRegisterUserService.removeById(id);
        return Result.success("ok");
    }

    @GetMapping("/autoJudge/{examId}")
    @SaCheckPermission("exam_add_update")
    public Result<String> autoJudge(@PathVariable("examId") Long examId) {
        examProblemService.autoJudge(examId);
        return Result.success("ok");
    }

    @GetMapping("/getNeedProblemList/{examId}")
    @SaCheckPermission("exam_add_update")
    public Result<List<NeedPeopleProblemVO>> getNeedProblemList(@PathVariable("examId") Long examId) {
        return Result.success(examService.getNeedProblemList(examId));
    }
}
